home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1998 May
/
Macworld (1998-05).dmg
/
Serious Demos
/
Lasso 2.5 Test Drive
/
Lasso 2.5 CGI
/
Java
/
DBInfo
/
DBInfo.java
< prev
next >
Wrap
Text File
|
1997-12-12
|
6KB
|
226 lines
/*
An applet which uses the LassoProxy API to get information about the currently open databases
and show it in list boxes.
Double-clicking on an item in a list shows information about that item. For instance, double-clicking on
a database name shows all its layouts. Double-clicking on a layout name show all its fields.
Double-clicking on a field name shows its value lists (if any).
- Kyle Jessup kylej@blueworld.com
*/
import java.awt.*;
import java.applet.Applet;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;
public class DBInfo extends Applet
{
protected List fDatabases = null;
protected List fLayouts;
protected List fFields;
protected List fValues;
protected LassoProxy fProxy;
// to run this stand-alone, set this to true, then change to URL in the getDocumentbase method
// to the url of the server
protected final static boolean gRunLocal = false;
public void init()
{
if (fDatabases == null)
{
setBackground(Color.white);
String l = getParameter("lasso_name");
if (l == null || l.length() == 0)
{
System.out.println("Could not find \"lasso_name\" param.");
return;
}
setLayout(new GridBagLayout());
fDatabases = new List(15, false);
fLayouts = new List(15, false);
fFields = new List(15, false);
fValues = new List(15, false);
GBConstrainer.constrain(this, new Label("Databases"), 0, 0);
GBConstrainer.constrain(this, new Label("Layouts"), 0, 1);
GBConstrainer.constrain(this, new Label("Fields"), 0, 2);
GBConstrainer.constrain(this, new Label("Values"), 0, 3);
GBConstrainer.constrain(this, fDatabases, 1, 0);
GBConstrainer.constrain(this, fLayouts, 1, 1);
GBConstrainer.constrain(this, fFields, 1, 2);
GBConstrainer.constrain(this, fValues, 1, 3);
// create the proxy object we will use repeatedly
fProxy = new LassoProxy(getDocumentBase(), l);
}
else
{
fDatabases.clear();
fLayouts.clear();
fFields.clear();
fValues.clear();
}
try
{
// retrieve all the database names so we can show them
String[] names = fProxy.databaseNames();
// add each name to the list
for (int i = 0; i < names.length; ++i)
fDatabases.addItem(names[i]);
}
catch(IOException e)
{ System.out.println(e.toString()); }
repaint();
}
public URL getDocumentBase()
{
try
{
if (gRunLocal)
return new URL("http://209.19.18.245/");
return super.getDocumentBase();
}
catch(MalformedURLException e){}
return null;
}
public boolean action(Event evt, Object what)
{
if (evt.target == fDatabases)
updateLayouts();
else if (evt.target == fLayouts)
updateFields();
else if (evt.target == fFields)
if (!showImage()) updateValues();
return true;
}
// an image field was double-clicked
// retrieve a record at random and try to display the image
protected boolean showImage()
{
String fieldName = fFields.getSelectedItem();
int index = fieldName.indexOf(" - Image!");
if (index == -1) return false;
LassoRequest req = new LassoRequest(getParameter("lasso_name"));
req.setDatabaseName(fDatabases.getSelectedItem());
req.setLayoutName(fLayouts.getSelectedItem());
req.setAction(LassoRequest.RANDOM);
LassoProxy proxy = new LassoProxy(getDocumentBase(), getParameter("lasso_name"));
try
{
LassoResponse response = proxy.processRequest(req);
req.setRecordID(response.recordID(0));
ImageWindow m = new ImageWindow(proxy.getGIF(req, fieldName.substring(0, index), 8, false));
m.resize(m.getImage().getWidth(m), m.getImage().getHeight(m));
}
catch(IOException e)
{ System.out.println(e.toString()); return false; }
return true;
}
// add the layout names from the selected database to the list
protected void updateLayouts()
{
showStatus("Updating layouts...");
String dbName = fDatabases.getSelectedItem();
if (dbName == null || dbName.length() == 0) return;
try
{
String[] lNames = fProxy.layoutNames(dbName);
fLayouts.clear();
fFields.clear();
fValues.clear();
for (int i = 0; i < lNames.length; ++i)
fLayouts.addItem(lNames[i]);
}
catch(IOException e)
{ System.out.println(e.toString()); }
showStatus("");
}
// get all the field names from the selected database and layout and add them to the list.
protected void updateFields()
{
showStatus("Updating fields...");
try
{
String layoutName = fLayouts.getSelectedItem();
if (layoutName == null || layoutName.length() == 0) return;
LassoRequest request = new LassoRequest(fProxy.getLasso());
request.setAction(LassoRequest.FIELD_INFO);
request.setDatabaseName(fDatabases.getSelectedItem());
request.setLayoutName(layoutName);
LassoResponse response = fProxy.processRequest(request);
fFields.clear();
fValues.clear();
for (int i = 0; i < response.fieldNames().length; ++i)
{
if (response.fieldType(response.fieldIndex(response.fieldNames()[i])) == LassoResponse.IMAGE)
{
fFields.addItem(response.fieldNames()[i] + " - Image!");
}
else
fFields.addItem(response.fieldNames()[i]);
}
}
catch(IOException e)
{ System.out.println(e.toString()); }
catch(FieldNotFoundException e)
{ System.out.println(e.toString()); }
finally
{ showStatus(""); }
}
// update the valuelists of the double-clicked field
protected void updateValues()
{
showStatus("Updating values...");
String fieldName = fFields.getSelectedItem();
if (fieldName == null || fieldName.length() == 0) return;
LassoRequest request = new LassoRequest(fProxy.getLasso());
request.setAction(LassoRequest.FIELD_INFO);
request.setDatabaseName(fDatabases.getSelectedItem());
request.setLayoutName(fLayouts.getSelectedItem());
try
{
LassoResponse response = fProxy.processRequest(request);
fValues.clear();
int index = response.fieldIndex(fieldName);
for (int i = 0; i < response.fieldValueList(index).length; ++i)
fValues.addItem(response.fieldValueList(index)[i]);
}
catch(IOException e)
{ System.out.println(e.toString()); }
catch(FieldNotFoundException e)
{ System.out.println(e.toString()); }
finally
{ showStatus(""); }
}
}